package regexppractice;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @description:
 * @author: jhy
 * @time: 2021/6/1 13:15
 */


//匹配汉字
public class RegExpDemo1 {

    public static void main(String[] args) {
        String content = "：正则表达式hhhhh";
        String regExp = "[\u4e00-\u9fa5]";

        //(1)创建一个正则表达式对象Pattern，里面传入字符串匹配逻辑
        Pattern pattern = Pattern.compile(regExp);

        //2.创建一个匹配器对象Matcher
        //过程：matcher匹配器按照pattern模式，到content中进行匹配
        Matcher matcher = pattern.matcher(content);
        //开始循环匹配，匹配就返回true，否则返回false
        while (matcher.find()){
            System.out.println("找到汉字："+matcher.group(0));
        }

    }
}
